/*
 * © 2010 Autodata Solutions Company. All Rights Reserved
 * This source code is the confidential and proprietary information of Autodata Solutions Company.
 * The user shall not, in whole or in part, copy, publish, disclose or make any use of this source code
 * without the prior written consent of Autodata Solutions Company.
 */
Ext.ns('net.autodata.modelwalk.ModelComboBox');
(function () {
	
	var Reader = function ()
    {
        return new Ext.data.JsonReader({
            idProperty: 'code',
            root: '',
            fields: [
                {name: 'modelCode', mapping: 'code'},
                {name: 'description', sortType: Ext.data.SortTypes.asUCString, convert: function (v) {
                	if (v) {
                		return v.replace('&amp;', '&');
                	} else {
                		return '';
                	}
                }}
            ]
        });
    };
	
    /**
     * @class ModelComboBox
     * @extends net.autodata..form.DependentComboBox
     * @namespace net.autodata.modelwalk
     */
	var ModelComboBox = Ext.extend(net.autodata.form.DependentComboBox, {
		
		/**
		 * xtype = acompare-mw-modelcombo
		 * @method constructor
		 * @param {Object} cfg
		 */
		constructor: function (cfg)
		{	
			cfg = cfg ||{};

            var storeCfg = cfg.storeCfg || {};
            delete cfg.storeCfg;
						
            Ext.apply(storeCfg, {
                autoDestroy: true,
                proxy: new net.autodata.modelwalk.data.ModelProxy(),
                reader: new Reader()
            }, {
                autoLoad: false,
                remoteSort: false,
                sortInfo: {
                	field: 'description',
                	direction: 'ASC'
                }
            });
            
            var store = new Ext.data.Store(storeCfg);

            Ext.applyIf(cfg, {
                allowBlank: true,
                emptyText: ASC.message('net.autodata.modelwalk.label.please-select'),
                forceSelection: true,
                lazyInit: false,
                mode: 'local',
                selectOnFocus:true,
                triggerAction: 'all',
                typeAhead: true,
                width: 200
            });

            Ext.apply(cfg, {
                displayField: 'description',
                store: store,
                valueField: 'modelCode'
            });

			
			ModelComboBox.superclass.constructor.call(this, cfg);
		}
	});
	
	net.autodata.modelwalk.ModelComboBox = ModelComboBox;	
	
	Ext.reg('acompare-mw-modelcombo', net.autodata.modelwalk.ModelComboBox);
})();
